<template>
	<view :class="themeName">
		<view class="center-box p-20">
			<view class="leader-info p-20 flex">
				<view class="m-r-20">
					<image class="avatar" :src="$getImageUri(leaderInfo.avatar)"></image>
				</view>
				<view class="info">
					<view class="name flex">
						<text>{{leaderInfo.name}}</text>
						<view class="badge m-l-10" :style="{
							backgroundImage: `url(${$getImageUri('resource/image/shopapi/uniapp/leader-badge.png')})`
						}">{{$zhTran('团长')}}</view>
					</view>
					<view>{{$zhTran('联系电话: ')}}{{leaderInfo.phone}}</view>
					<view>{{$zhTran('提货地址: ')}}{{leaderInfo.region_address}}</view>
				</view>
				<view class="change-leader" @click="chooseLeader">{{$zhTran('切换团长')}}</view>
			</view>
		</view>

		<mescroll-uni ref="mescrollRef" :fixed="false" :up="{
				  auto: false,
				  noMoreSize: 3,
				  empty: {
				  	icon: $getImageUri('resource/image/shopapi/uniapp/empty/order.png'),
				  	tip: $zhTran('暂无团购活动~'),
				  	fixed: true
				  }
			  }" :down="{ auto: false }" @init="mescrollInit" @down="downCallback" @up="upCallback">

			<view class="activity-item p-l-20 m-t-20" v-for="orderItem,idx in actList" :key="idx">
				<view class="title flex row-between">
					<view class="flex col-center">
						<view class="act-name wait">{{orderItem.name}}</view>
						<view class="wait-start m-l-10" :style="{
							backgroundImage: `url(${$getImageUri('resource/image/shopapi/uniapp/count-times.png')})`
						}" v-if="orderItem.status==0">{{$zhTran('即将开始')}}</view>
						<view class="hot-act m-l-10" :style="{
							backgroundImage: `url(${$getImageUri('resource/image/shopapi/uniapp/hot-act-icon.png')})`
						}" v-if="orderItem.status==1">{{$zhTran('抢购中')}}</view>
					</view>
					<view class="user-buy m-r-20">
						<count-down :time-end="orderItem.start_time" color="rgba(74, 25, 0, 1)"
							separator-color="rgba(38, 38, 38, 1)" bg-color="rgba(255, 208, 0, 1)"
							v-if="orderItem.status==0" />
						<view class="flex col-center" v-if="orderItem.status==1 && orderItem.buy_user > 0">
							<image :src="item" v-for="item,idx2 in orderItem.buy_avatar" :key="idx2">
							</image>
							<view class="text m-l-10">{{$zhTran('等'+orderItem.buy_user+'人已抢'+orderItem.buy_count+'件')}}
							</view>
						</view>
					</view>
				</view>
				<scroll-view class="goods-swiper m-t-20" :scroll-x="true">
					<view class="goods goods--square" v-for="item in orderItem.goods" :key="item.id">
						<view class="goods-images">
							<u-image width="100%" height="100%" :src="item.goods_image" mode="aspectFit" />
						</view>
						<!-- 商品信息 -->
						<view class="goods-content">
							<!-- 名称 -->
							<view class="goods-name line-2">
								<slot name="name">{{ item.goods_name }}</slot>
							</view>
							<!-- 价格 -->
							<view class="goods-other">
								<slot>
									<price :content="item.max_price" main-size="42rpx" minor-size="36rpx"
										:prefix="price_symbol" :color="themeColor">
										<view slot="suffix">
											<price class="muted sm m-l-12" :line-through="true" :prefix="price_symbol"
												:color="fieldStyles.scribing_price_color" slot="suffix"
												:content="item.sell_price"
												v-show="Number(item.sell_price) && fieldShowHide.show_scribing_price" />
										</view>
									</price>
								</slot>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</mescroll-uni>

	</view>
</template>

<script type="text/javascript">
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		location_key
	} from "@/config/app";
	import {
		apiCommunityGroupPurchaseNearLeaderActivityList,
	} from "@/api/community_group_purchase"
	import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
	export default {
		mixins: [MescrollMixin],
		props: {},
		data() {
			return {
				actList: [],
				location: {}, // 我的位置
				authLocation: 0,
				price_symbol: '￥',
				fieldShowHide: {
					show_goods_model: 0,
					show_goods_stock: 0,
					show_gfa_flag: 0,
					show_goods_code: 0,
					show_goods_tag: 0,
					show_cgp_tag: 0,
					show_scribing_price: 1,
				},
				fieldStyles: {
					price_color: '#FA4034'
				},
				leaderInfo: {
					name: '',
					avatar: '/resource/image/shopapi/default/avatar.png',
					phone: '',
					region_address: ''
				}
			}
		},
		methods: {
			// 上拉加载更多
			upCallback({
				num,
				size
			}) {
				apiCommunityGroupPurchaseNearLeaderActivityList({
					leader_id: this.leader_id,
					location: this.location,
					mapkey: location_key,
					authLocation: this.authLocation,
					page_no: num,
					page_size: size,
				}).then(({
					lists,
					count,
					leader
				}) => {
					if (num === 1) this.actList = []
					if (num === 1) this.leaderInfo = this.$zhTran(leader)

					this.actList = [...this.actList, ...lists]
					this.actList = this.$zhTran(this.actList)
					this.mescroll.endSuccess(lists.length, count)
				}).catch(err => {
					this.mescroll.endErr()
				})
			},
			chooseLeader() {
				this.$Router.replaceAll({
					path: "/bundle2/pages/community_group_purchase/user/user_center",
					query: {
						leader_id: this.leader_id,
					},
				});
			}
		},
		computed: {},
		onLoad() {
			const options = this.$Route.query;
			this.leader_id = options.leader_id
			if (this.$Route.meta.atitle) {
				uni.setNavigationBarTitle({
					title: this.$zhTran(this.$Route.meta.atitle)
				})
			}

			// 防止获取不到mescroll
			setTimeout(() => {
				this.mescroll.resetUpScroll()
			}, 200)
		},
	};
</script>

<style lang="scss" scoped>
	.center-box {

		.leader-info {
			width: 100%;
			background-color: #fff;
			position: relative;
			border-radius: 10rpx;

			.avatar {
				width: 110rpx;
				height: 110rpx;
				border-radius: 50%;
				border: 1px solid #f8f8f8;
			}

			.info {
				width: calc(100% - 100rpx);
				color: rgba(166, 166, 166, 1);
				font-size: 24rpx;

				&>view {
					margin-bottom: 10rpx;
				}

				.name {
					color: rgba(38, 38, 38, 1);
					font-size: 28rpx;
					font-weight: bold;

					.badge {
						background-repeat: no-repeat;
						background-size: 100% 100%;
						color: #fff;
						padding: 6rpx 15rpx;
						font-size: 22rpx;
					}
				}
			}

			.change-leader {
				background-color: rgba(255, 208, 0, 1);
				color: rgba(74, 25, 0, 1);
				font-size: 24rpx;
				padding: 8rpx 14rpx;
				position: absolute;
				top: 20rpx;
				right: 20rpx;
				border-radius: 4rpx;
			}

		}
	}

	.activity-item {
		.title {
			.act-name {
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				word-break: break-all;
				max-width: 290rpx;
				padding: 14rpx 0 8rpx 0;
				font-weight: bold;
				font-size: 32rpx;

				&.wait {
					max-width: 260rpx;
					margin-top: 7rpx;
				}
			}

			.hot-act {
				background-repeat: no-repeat;
				background-size: 100% 100%;
				color: #fff;
				padding: 14rpx 15rpx 8rpx 50rpx;
				font-size: 22rpx;
			}

			.wait-start {
				width: 170rpx;
				background-repeat: no-repeat;
				background-size: 100% 100%;
				color: #fff;
				padding: 6rpx 0 6rpx 56rpx;
				margin-top: 12rpx;
				font-size: 22rpx;
			}

			.user-buy {
				padding-top: 12rpx;

				.text {
					float: left;
					font-size: 22rpx;
					color: rgba(166, 166, 166, 1);
				}

				image {
					float: left;
					margin-left: -15rpx;
					width: 46rpx;
					height: 46rpx;
					border-radius: 100%;
					border: 2px solid #ffffff;
					box-sizing: border-box;
				}
			}
		}
	}

	.goods-swiper {
		width: 100%;
		height: 460rpx;
		white-space: nowrap;

		.goods {
			display: inline-block;
			border-radius: 7px;
			background-color: #ffffff;
			overflow: hidden;
			margin-right: 20rpx;
			white-space: normal;

			&--square {
				flex-direction: column;
				width: 307rpx;
				min-height: 460rpx;

				.goods-images {
					width: 305rpx;
					height: 305rpx;
				}

				.goods-content {
					padding: 14rpx;
				}
			}

			&-content {
				box-sizing: border-box;
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				height: 100%;
				position: relative;

				.goods-other {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
				}
			}
		}
	}
</style>